home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
014a
/
clrlaser.zip
/
LASER.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1991-03-03
|
6KB
|
244 lines
PROGRAM LASER;{ colourful display on VGA.. March 1991}
{$R-}
{$I-}
uses dos,crt,gcolor,graph,drivers, fonts;
const
c1 = 150; {75;}
c2 = 18; {9; }
c3 = 6; {3; }
maxindex = 150;
ymin = 0;
ymax = 479;
xmin = 0;
xmax = 639;
maxcolor = 15;
space = ' ';
red = 8;
blue = 7;
green = 2;
TYPE
irange = 0..maxindex;
screencolor = 0..maxcolor;
linerec = RECORD
x1, x2: integer;
y1, y2 : integer;
color :screencolor;
END; { record}
VAR
color : screencolor;
erasing : boolean;
x1, x2 : integer;
y1, y2 : integer;
index : irange;
current_color : screencolor;
laser_is_4 : boolean ; { laser_is_4 if true, else only one}
laser_is_2 : boolean ; { laser_is_2 if true, else only one}
temp,count1,count2, dx1, dx2, dy1, dy2,x,y : integer;
linearray : ARRAY [ irange ] OF linerec;
f : text;
ch : char;
graphdriver, graphmode, errorcode: integer;
w,c,n : integer;
PROCEDURE ginit; { INITIALIZE vga 640X480 GRAPHICS}
begin
graphdriver := detect;
InitGraph(graphdriver,graphmode, '');
Errorcode:=graphresult;
if errorcode <>grOK then
begin
writeln ('graphics error', GrapherrorMsg(errorcode));
writeln('program aborting..');
halt (1);
end;
end;
PROCEDURE startup; { welcome user, general setup}
var p,l : integer;
procedure WSTRING (S:STRING; A,B : INTEGER);
BEGIN
TextColor(B);
GoToXY(p,l);
Write(s);
END;{wstring}
BEGIN
p := 40;
Setcolor (red); rectangle (p,p,xmax-p,ymax-p);
p := 45;
Setcolor (blue); rectangle (p,p,xmax-p,ymax-p);
p := 50;
Setcolor (green); rectangle (p,p,xmax-p,ymax-p);
p := 10; l := 5;
GoToXY (p,l);
wstring ('Welcome to',0,2);
p := 20; l := 6;
wstring(' *** Lasergraph ***',0,5);
p := 10; l:=10;
wstring ('<ESC> will terminate',0,7);
l:= 12;
wstring ('<SPACE> will freeze and',0,9);
l := 14;
wstring ('restart the display',0,9);
l := 18;
wstring ('tell me the number of lasers',0,11);
l := 20;
wstring (' Press <1> <2> or <4>',0,11);
ch := '0'; laser_is_4 := false; laser_is_2 := false;
repeat
ch := readkey;
until ch in [ '1','2','4'];
if ch = '2' then laser_is_2 := true;
if ch = '4' then laser_is_4 := true;
if ch = '4' then laser_is_2 := true;
GoToXY (16,182);
end; { startup}
PROCEDURE initialize;
begin
x1 := xmin; x2 := xmin;
y1 := ymin; y2 := ymin;
color := 0;
index := 0;
count1 := 0;
count2 := 0;
ch := chr(0);
erasing := false;
randomize;
END; { initialize}
PROCEDURE newstep; { return new dx, dy .. delta }
BEGIN
dx1 := random (c2 - c3);
dx2 := random (c2 - c3);
dy1 := random (c2 - c3);
dy2 := random (c2 - c3);
count2:= random (c1 - 1);
END; { newstep}
PROCEDURE eraseline (lline:linerec);
BEGIN
WITH LLINE DO
BEGIN
Setcolor (0);
line(x1,y1,x2,y2); { black out the line in color 0 (bkgnd) }
if laser_is_2 THEN
line(xmax-x1,ymax-y1,xmax-x2,ymax-y2);
if laser_is_4 then
BEGIN
line(xmax-x1,y1,xmax-x2,y2);
line(x1,ymax-y1,x2,ymax-y2);
END;
END;
END; { eraseline}
PROCEDURE computenew{(var x1,x2:xrange ; y1,y2:yrange )};
{ calc new x and y }
PROCEDURE newcoord (var n,change: integer; min,max : integer);
{ calc new co-ord n; of change; within min, max }
VAR
temp: integer;
BEGIN
temp := n + change;
IF ( temp < min ) OR ( temp > max)
THEN change := - change
ELSE n := temp
END; { newcoord}
BEGIN { computenew }
newcoord ( x1, dx1, xmin, xmax );
newcoord ( y1, dy1, ymin, ymax );
newcoord ( x2, dx2, xmin, xmax );
newcoord ( y2, dy2, ymin, ymax )
END; { computenew}
PROCEDURE storedata ( xx1,xx2:integer; yy1,yy2:integer;
current_color : screencolor; index :irange ) ;
{ save line in array at index }
BEGIN
WITH linearray [ index ] DO
BEGIN
x1 := xx1; x2 := xx2;
y1 := yy1; y2 := yy2;
color := current_color;
END; { with }
END ; { storedata}
BEGIN {main}
ginit;
startup;
initialize ;
ClearViewport;
current_color := maxcolor;
REPEAT { until <esc> }
IF index = maxindex
THEN
BEGIN
index := 1; erasing := true
END
ELSE
index := index + 1;
IF erasing
then eraseline (linearray [ index] );
IF count1 = 0
THEN { return new color and count1}
BEGIN
current_color := random (maxcolor - 1) + 1 ;
count1 := random ( c1) + 1;
END; { newcolor}
IF count2 = 0
THEN newstep { returning dx1,dy1,dx2,dy2,
and new random count2} ;
count1 := count1 -1;
count2 := count2 -1;
computenew{(x1, x2, y1, y2 )};
storedata ( { saving} x1,x2,y1,y2, current_color,
{ in array using } index );
SetColor(current_color);
line(x1,y1,x2,y2);
IF laser_is_2 then
line(xmax-x1,ymax-y1,xmax-x2,ymax-y2);
IF laser_is_4 then
BEGIN
line(xmax-x1,y1,xmax-x2,y2);
line(x1,ymax-y1,x2,ymax-y2);
END;
IF keypressed THEN
BEGIN
repeat
ch := readkey;
UNTIL(ch =space)or(ch =chr(27));
END;
UNTIL ch = chr(27);
CloseGraph;
END.